package com.ericcson.innerportalapp;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ListFragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class OfficeListFragment extends ListFragment {
	
	public interface OnGetOfficeList {
		public ArrayList<Office> getOfficeList();
	}
	
	private OnGetOfficeList onGetOfficeList;
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		
		super.onListItemClick(l, v, position, id);
		
		Office office = onGetOfficeList.getOfficeList().get(position);
		String latitudeStr, longtitudeStr;
		latitudeStr = String.valueOf(office.getLatitute());
		longtitudeStr = String.valueOf(office.getLongtitute());
	
		Uri uri1 = Uri.parse("geo:0,0?q=" + longtitudeStr + "," + latitudeStr + "("+office.getName() +")&?z=8");
		Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri1);
		startActivity(intent);
	}
	
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);

		try {
			onGetOfficeList = (OnGetOfficeList) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
					+ " must implement onGetOfficeList");
		}
	}
	

}
